find_program(LEMON_BIN lemon)
find_program(SED_BIN sed)

add_custom_command(
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/parser.cly
  COMMAND ${SED_BIN} 's/\;\;//g' ${CMAKE_CURRENT_SOURCE_DIR}/parser.ly
  > ${CMAKE_CURRENT_BINARY_DIR}/parser.cly
  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/parser.ly
  )

add_custom_command(
  OUTPUT
		${CMAKE_CURRENT_BINARY_DIR}/parser.c
		${CMAKE_CURRENT_BINARY_DIR}/parser.h
  COMMAND
		${LEMON_BIN} -c ${CMAKE_CURRENT_BINARY_DIR}/parser.cly 
  DEPENDS
		${CMAKE_CURRENT_BINARY_DIR}/parser.cly)

add_library(jparse
  ${CMAKE_CURRENT_BINARY_DIR}/parser.c)

include_directories(
  ${CMAKE_SOURCE_DIR}/bstrlib
  ${CMAKE_SOURCE_DIR}/scanner
  ${CMAKE_CURRENT_BINARY_DIR})

add_executable(jparse_test
  test.c)
target_link_libraries(jparse_test
  jparse)